#
import json
import os
import gzip
import sys
from pathlib import Path

def get_offest(data:bytes,index:slice):
    return int.from_bytes(data[index],byteorder='little')*8

def main():
    bin_path='/root/vpd/0xae_eeprom.bin'
    with open(bin_path,'rb') as f:
        data=f.read()
    
    csr_offset=get_offest(data,slice(21,23))
    sig_offset=get_offest(data,slice(23,25))

    csr_str=gzip.decompress(data[(csr_offset+56):sig_offset]).decode()
    with open("out.json",'w') as fp:
        json.dump(json.loads(csr_str),fp,indent=4)


if __name__=="__main__":
    main()